package com.ping.study.controller.tx;

import com.ping.study.model.dto.tx.MatchListRequest;
import com.ping.study.service.tx.MatchService;
import com.ping.study.service.tx.SportsQqService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

import java.time.LocalDate;
import java.util.List;

@RestController
@RequestMapping("/tx/nba")
public class MatchController {
    private final SportsQqService sportsQqService;
    private final MatchService matchService;

    public MatchController(MatchService matchService,SportsQqService sportsQqService) {
        this.sportsQqService = sportsQqService;
        this.matchService = matchService;
    }

    @GetMapping("/matches")
    public Mono<String> getMatches(
            @RequestParam(required = false, defaultValue = "100000") Integer columnId,
            @RequestParam(required = false) String startTime,
            @RequestParam(required = false) String endTime) {

        MatchListRequest request = new MatchListRequest();
        request.setColumnId(columnId);

        LocalDate currentDate = LocalDate.now();
        request.setStartTime(startTime != null ? LocalDate.parse(startTime) : currentDate);
        request.setEndTime(endTime != null ? LocalDate.parse(endTime) : currentDate);

        return sportsQqService.getMatchList(request);
    }

    @GetMapping("/lives")
    public List<String> getPlayoffLiveIds(
            @RequestParam String startTime,
            @RequestParam String endTime) {

        LocalDate startDate = LocalDate.parse(startTime);
        LocalDate endDate = LocalDate.parse(endTime);

        return matchService.getPlayoffLiveIdsBlocking(startDate, endDate);
    }
}